﻿using System.Collections;
using System.Collections.Generic;
using LitJson;
using UnityEngine;

public class SendMsgRequest : BaseRequest
{

	private ChatPanel _chatPanel;
	protected override void Awake()
	{
		_controllerType = ControllerType.CHAT;
		_methodType = MethodType.SEND_MSG;
		base.Awake();
	}

	// Use this for initialization
	void Start () {
		//组件初始化
		_chatPanel = this.gameObject.GetComponent<ChatPanel>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void SendRequest(int chatId,string msg)
	{
		JsonData requestJsonData =new JsonData();
		requestJsonData["chatId"] = chatId;
		requestJsonData["msg"] = msg;
		NettyRequest nettyRequest = new NettyRequest();
		nettyRequest.controllerType = (int) _controllerType;
		nettyRequest.methodType = (int) _methodType;
		nettyRequest.data =JsonMapper.ToJson(requestJsonData);
		byte[] dataBytes = ConverterTool.SerialRequestObj(nettyRequest);
		UnityFacade.Instance.ClientManager.SendMsgToServer(dataBytes);
	}
	
	
	public override void OnResponse(string data)
	{
		JsonData respJsonData = JsonMapper.ToObject(data);
		_chatPanel.HandleSendMsgResponse(respJsonData);

	}

	
}
